{extend name="common/base" /}
{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body">
                            {include file="menu/form" /}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="my_js"}
<script>
    layui.use(['element', 'admin', 'form'], function () {
        var element = layui.element
            , admin = layui.admin
            , form = layui.form
            , $ = layui.$;
        admin.ajax('admin/menu', '', function (data) {
            if (data.code == 1001) {
                $.each(data.data, function (index, value) {
                    $('select[name="parent_id"]').append('<option value="' + value.id + '">' + value.label + '</option>');
                })
                form.render('select');
                form.val("menuEdit", {
                    "parent_id": '{$parent_id}'
                })
            } else {
                layer.msg(data.msg + '请联系管理员。');
            }
        }, '', 'get');
        form.on('submit(formMenu)', function (data) {
            admin.ajax('admin/menu', data.field, function (data) {
                if (data.code == 1001) {
                    $('#layui-icon-refresh',parent.document).click();
                    layer.confirm(data.msg + ',是否继续添加?', {
                        icon: 3,
                        title: '提示',
                        btn: ['继续', '返回']
                    }, function (index) {
                        location.reload();
                    }, function () {
                        admin.closeSelf()
                    });
                } else {
                    layer.msg(data.msg);
                }
            });
        });
    });
</script>
{/block}